package generater;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;

import com.fasterxml.jackson.databind.ObjectMapper;

import pojo.Book;

public class GenerateJsonFile {
	private Integer id;
	private String name;
	private Date publishDate;
	private String author;
	private Double price;
	private Boolean isNewBook;
	private String publisher;
	
	/***
	 * generate 10000 book record, parse into json and write to outside file
	 * @throws IOException
	 */
	public void generate() throws IOException{
		ObjectMapper mapper = new ObjectMapper();
		OutputStream outputStream = new FileOutputStream("Books.json");
		
		for(int i=1; i<=10000; i++){
			id=i;
			name="Book"+i;
			publishDate=new Date();
			author = "Jason"+i;
			price = 123.4;
			isNewBook = true;
			publisher = "OOCL"+i;
			Book book = new Book(id, name, publishDate, author, price, isNewBook, publisher);
			String string = mapper.writeValueAsString(book)+"\n";
			outputStream.write(string.getBytes());
		}
		outputStream.close();
	}
	
	public static void main(String[] args) throws IOException {
		new GenerateJsonFile().generate();
	}

}
